package com.zhx.real.mybatisplus.business;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 *describe: 树形菜单的基础类
 *
 *@author zhanghaixuan
 *@date 2018/09/20
 **/
@Data
public class TreeEntity <T extends Model> extends Model<T> {

	private static final long serialVersionUID = 1L;

	/**
	 * 唯一Id
	 */
	@TableId(value = "uid", type = IdType.ID_WORKER_STR)
	private String uid;
	/**
	 * 名称
	 */
	private String name;
	/**
	 * 父节点Id
	 */
	private String parentId;

	/**
	 * 全称
	 */
	@TableField(exist = false)
	protected String fullTitle;
	/**
	 * 是否底层节点
	 */
	@TableField(exist = false)
	protected boolean isBottom = false;
	/**
	 * 子节点列表
	 */
	@TableField(exist = false)
	protected List<TreeEntity> children = new ArrayList<>();

	public void add(TreeEntity node) {
		children.add(node);
	}

	@Override
	protected Serializable pkVal() {
		return this.uid;
	}
}
